This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.
Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter.
install.packages("forecast")
Installing package into ‘C:/Users/parmi/AppData/Local/R/win-library/4.2’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.2/forecast_8.18.zip'
Content type 'application/zip' length 1895007 bytes (1.8 MB)
downloaded 1.8 MB
package ‘forecast’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\parmi\AppData\Local\Temp\RtmpI5a4Fj\downloaded_packages
install.packages("plotly")
Installing package into ‘C:/Users/parmi/AppData/Local/R/win-library/4.2’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.2/plotly_4.10.1.zip'
Content type 'application/zip' length 3244124 bytes (3.1 MB)
downloaded 3.1 MB
package ‘plotly’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\parmi\AppData\Local\Temp\RtmpI5a4Fj\downloaded_packages
install.packages("tidyr")
Installing package into ‘C:/Users/parmi/AppData/Local/R/win-library/4.2’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.2/tidyr_1.2.1.zip'
Content type 'application/zip' length 967296 bytes (944 KB)
downloaded 944 KB
package ‘tidyr’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\parmi\AppData\Local\Temp\RtmpI5a4Fj\downloaded_packages
install.packages("dplyr")
Installing package into ‘C:/Users/parmi/AppData/Local/R/win-library/4.2’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.2/dplyr_1.0.10.zip'
Content type 'application/zip' length 1305081 bytes (1.2 MB)
downloaded 1.2 MB
package ‘dplyr’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\parmi\AppData\Local\Temp\RtmpI5a4Fj\downloaded_packages
library(forecast)
Registered S3 method overwritten by 'quantmod':
method from
as.zoo.data.frame zoo
data(EuStockMarkets)
summary(EuStockMarkets)
DAX SMI CAC FTSE
Min. :1402 Min. :1587 Min. :1611 Min. :2281
1st Qu.:1744 1st Qu.:2166 1st Qu.:1875 1st Qu.:2843
Median :2141 Median :2796 Median :1992 Median :3247
Mean :2531 Mean :3376 Mean :2228 Mean :3566
3rd Qu.:2722 3rd Qu.:3812 3rd Qu.:2274 3rd Qu.:3994
Max. :6186 Max. :8412 Max. :4388 Max. :6179
class(EuStockMarkets)
[1] "mts" "ts" "matrix"
par(mfrow=c(4,1))
x <- seq_len(nrow(EuStockMarkets))
for (i in seq_len(ncol(EuStockMarkets))) {
y <- EuStockMarkets[,i]
heading <- colnames(EuStockMarkets)[i]
plot(x, y, type="n", main = heading, xaxt = "n")
lines(x, EuStockMarkets[,i])
years <- as.integer(time(EuStockMarkets))
tick.posis <- seq(10, length(years), by = 100)
axis(1, at = tick.posis, las = 2, labels = years[tick.posis])
}
plot(EuStockMarkets)
library(plotly)
Loading required package: ggplot2
Registered S3 method overwritten by 'data.table':
method from
print.data.table
Registered S3 method overwritten by 'htmlwidgets':
method from
print.htmlwidget tools:rstudio
Attaching package: ‘plotly’
The following object is masked from ‘package:ggplot2’:
last_plot
The following object is masked from ‘package:stats’:
filter
The following object is masked from ‘package:graphics’:
layout
library(tidyr)
library(dplyr)
Attaching package: ‘dplyr’
The following objects are masked from ‘package:stats’:
filter, lag
The following objects are masked from ‘package:base’:
intersect, setdiff, setequal, union
stocks <- as.data.frame(EuStockMarkets) %>%
gather(index, price) %>%
mutate(time = rep(time(EuStockMarkets), 4))
plot_ly(stocks, x = ~time, y = ~price, color = ~index, mode = "lines")
No trace type specified:
Based on info supplied, a 'scatter' trace seems appropriate.
Read more about this trace type -> https://plotly.com/r/reference/#scatter
No trace type specified:
Based on info supplied, a 'scatter' trace seems appropriate.
Read more about this trace type -> https://plotly.com/r/reference/#scatter
ftse=(EuStockMarkets[,4])
plot(ftse)
components.ts = decompose(ftse)
plot(components.ts)
fit_ftse <- auto.arima(ftse, trace=TRUE)
Fitting models using approximations to speed things up...
ARIMA(2,1,2)(1,0,1)[260] with drift : Inf
ARIMA(0,1,0) with drift : 17994.59
ARIMA(1,1,0)(1,0,0)[260] with drift : Inf
ARIMA(0,1,1)(0,0,1)[260] with drift : Inf
ARIMA(0,1,0) : 17997.78
ARIMA(0,1,0)(1,0,0)[260] with drift : Inf
ARIMA(0,1,0)(0,0,1)[260] with drift : Inf
ARIMA(0,1,0)(1,0,1)[260] with drift : Inf
ARIMA(1,1,0) with drift : 17968.54
ARIMA(1,1,0)(0,0,1)[260] with drift : Inf
ARIMA(1,1,0)(1,0,1)[260] with drift : Inf
ARIMA(2,1,0) with drift : 17970.46
ARIMA(1,1,1) with drift : 17969.53
ARIMA(0,1,1) with drift : 17966.98
ARIMA(0,1,1)(1,0,0)[260] with drift : Inf
ARIMA(0,1,1)(1,0,1)[260] with drift : Inf
ARIMA(0,1,2) with drift : 17968.91
ARIMA(1,1,2) with drift : Inf
ARIMA(0,1,1) : 17969.15
Now re-fitting the best model(s) without approximations...
ARIMA(0,1,1) with drift : 17973.84
Best model: ARIMA(0,1,1) with drift
forecaste_ftse <- forecast(fit_ftse, 50)
plot(forecaste_ftse, main = "Graph with forecasting of ftse",col.main = "darkgreen")
print(forecaste_ftse)
cac=(EuStockMarkets[,3])
plot(cac)
components.ts = decompose(cac)
plot(components.ts)
fit_cac <- auto.arima(cac, trace=TRUE)
Fitting models using approximations to speed things up...
ARIMA(2,2,2)(1,0,1)[260] : Inf
ARIMA(0,2,0) : 18628.27
ARIMA(1,2,0)(1,0,0)[260] : Inf
ARIMA(0,2,1)(0,0,1)[260] : Inf
ARIMA(0,2,0)(1,0,0)[260] : Inf
ARIMA(0,2,0)(0,0,1)[260] : Inf
ARIMA(0,2,0)(1,0,1)[260] : Inf
ARIMA(1,2,0) : 18120.13
ARIMA(1,2,0)(0,0,1)[260] : Inf
ARIMA(1,2,0)(1,0,1)[260] : Inf
ARIMA(2,2,0) : 17967.71
ARIMA(2,2,0)(1,0,0)[260] : Inf
ARIMA(2,2,0)(0,0,1)[260] : Inf
ARIMA(2,2,0)(1,0,1)[260] : Inf
ARIMA(3,2,0) : 17841.46
ARIMA(3,2,0)(1,0,0)[260] : Inf
ARIMA(3,2,0)(0,0,1)[260] : Inf
ARIMA(3,2,0)(1,0,1)[260] : Inf
ARIMA(4,2,0) : 17783.76
ARIMA(4,2,0)(1,0,0)[260] : Inf
ARIMA(4,2,0)(0,0,1)[260] : Inf
ARIMA(4,2,0)(1,0,1)[260] : Inf
ARIMA(5,2,0) : 17694.23
ARIMA(5,2,0)(1,0,0)[260] : Inf
ARIMA(5,2,0)(0,0,1)[260] : Inf
ARIMA(5,2,0)(1,0,1)[260] : Inf
ARIMA(5,2,1) : 17427.49
ARIMA(5,2,1)(1,0,0)[260] : Inf
ARIMA(5,2,1)(0,0,1)[260] : 17429.08
ARIMA(5,2,1)(1,0,1)[260] : Inf
ARIMA(4,2,1) : Inf
ARIMA(5,2,2) : Inf
ARIMA(4,2,2) : Inf
Now re-fitting the best model(s) without approximations...
ARIMA(5,2,1) : Inf
print(forecaste_cac)
smi=(EuStockMarkets[,2])
plot(smi)
components.ts = decompose(smi)
plot(components.ts)
fit_smi <- auto.arima(smi, trace=TRUE)
forecaste_smi <- forecast(fit_smi, 50)
plot(forecaste_smi, main = "Graph with forecasting of smi",col.main = "darkgreen")
print(forecaste_smi)
dax=(EuStockMarkets[,1])
plot(dax)
components.ts = decompose(dax)
plot(components.ts)
fit_dax <- auto.arima(dax, trace=TRUE)
forecaste_dax <- forecast(fit_dax, 50)
plot(forecaste_dax, main = "Graph with forecasting of dax",col.main = "darkgreen")
print(forecaste_dax)